package com.jlnk.stockdemo.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.jlnk.stockdemo.R;
import com.jlnk.stockdemo.bean.SpotListResponse;

import java.util.List;

public class SpotAdapter extends RecyclerView.Adapter<SpotAdapter.SpotViewHolder> {
    private List<SpotListResponse.Data.Spot> spotItems;

    public SpotAdapter(List<SpotListResponse.Data.Spot> spotItems) {
        this.spotItems = spotItems;
    }

    @Override
    public SpotViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_spot_list, parent, false);
        return new SpotViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(SpotViewHolder holder, int position) {
        SpotListResponse.Data.Spot spotItem = spotItems.get(position);
        holder.tv_ts_name.setText((String) spotItem.getTs_name());
        holder.tv_trade_type.setText((String) spotItem.getTrade_type());
        holder.tv_t_unit.setText((String) spotItem.getT_unit());
        holder.tv_trade_mode.setText((String) spotItem.getTrade_mode());
        holder.tv_margin_rate.setText((String) spotItem.getMargin_rate());

    }

    @Override
    public int getItemCount() {
        return spotItems.size();
    }

    public static class SpotViewHolder extends RecyclerView.ViewHolder {
        TextView tv_ts_name;
        TextView tv_trade_type;
        TextView tv_t_unit;
        TextView tv_trade_mode;
        TextView tv_margin_rate;

        public SpotViewHolder(View itemView) {
            super(itemView);
            tv_ts_name = itemView.findViewById(R.id.tv_ts_name);
            tv_trade_type = itemView.findViewById(R.id.tv_trade_type);
            tv_t_unit = itemView.findViewById(R.id.tv_t_unit);
            tv_trade_mode = itemView.findViewById(R.id.tv_trade_mode);
            tv_margin_rate = itemView.findViewById(R.id.tv_margin_rate);
        }
    }
}
